//package com.woniuxy.hotel.configuration;
//
//import java.util.LinkedHashMap;
//import java.util.Map;
//
//import javax.servlet.Filter;
//
//import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
//import org.apache.shiro.cache.ehcache.EhCacheManager;
//import org.apache.shiro.realm.Realm;
//import org.apache.shiro.spring.LifecycleBeanPostProcessor;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.DependsOn;
//
//import com.woniuxy.hotel.filter.RoleFilter;
//import com.woniuxy.hotel.realm.UserRealm;
//
//@Configuration
//public class ShiroConfig {
//
//	// 配置realm
//	@Bean
//	public UserRealm getRealm(HashedCredentialsMatcher hashedCredentialsMatcher) {
//		UserRealm realm = new UserRealm();
//		realm.setCredentialsMatcher(hashedCredentialsMatcher);
//		realm.setAuthenticationCachingEnabled(true);
//		realm.setAuthorizationCachingEnabled(true);
//		realm.setAuthenticationCacheName("authenticationCache");
//		realm.setAuthorizationCacheName("authorizationCache");
//		return realm;
//	}
//
//	// 安全管理器
//	@Bean
//	public DefaultWebSecurityManager getManager(UserRealm realm,EhCacheManager ehCacheManager) {
//		DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
//		manager.setRealm((Realm) realm);
//		manager.setCacheManager(ehCacheManager);
//		return manager;
//	}
//
//	//缓存管理
//	@Bean
//	public EhCacheManager cacheManager(){
//		EhCacheManager ehCacheManager=new EhCacheManager();
//		ehCacheManager.setCacheManagerConfigFile("classpath:config/ehcache.xml");
//		return ehCacheManager;
//	}
//
//	// 过滤器
//	@Bean
//	public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager manager) {
//		ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//		shiroFilterFactoryBean.setSecurityManager(manager);
//		// 没有认证，则跳转到登陆页面
//		shiroFilterFactoryBean.setLoginUrl("/login.html");
//		// 没有权限
//		shiroFilterFactoryBean.setUnauthorizedUrl("/error/500.html");
//		 //自定义拦截器
//        Map<String, Filter> FilterMap = new LinkedHashMap<>();
//        FilterMap.put("roleFilter", new RoleFilter());
//        shiroFilterFactoryBean.setFilters(FilterMap);
//		// 过滤器连
//		Map<String, String> map = new LinkedHashMap<>();// 需要保证有序
//		map.put("/login.html", "anon");
//		map.put("/user/login", "anon");
//		map.put("/user/rsByemail", "anon");
//		map.put("/user/rsPassword", "anon");
//		map.put("/user/loginCode", "anon");
//		map.put("/user/loginByPhone", "anon");
//		map.put("/getSMS", "anon");
//		map.put("/register", "anon");
//		map.put("/druid/**", "anon");
//		map.put("/assets/**", "anon");
//		map.put("/layui/**", "anon");
//		map.put("/style/**", "anon");
//
//		map.put("/logout", "logout");
//
//		map.put("/index.html", "authc,roleFilter[operator,superuser,admin]");
//		map.put("/vipInfo.html", "authc,roleFilter[operator,superuser,admin]");
//
//		map.put("/**", "authc");
//		shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
//		return shiroFilterFactoryBean;
//	}
//
//	@Bean
//	public HashedCredentialsMatcher getHashedCredentialsMatcher() {
//		HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
//		hashedCredentialsMatcher.setHashAlgorithmName("MD5");
//		hashedCredentialsMatcher.setHashIterations(1024);
//		return hashedCredentialsMatcher;
//	}
//
//	@Bean
//	public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
//		return new LifecycleBeanPostProcessor();
//	}
//
///*	@Bean
//	public RoleFilter roleFilter() {
//		return new RoleFilter();
//	}*/
//
//	/**
//	 * 开启Shiro的注解(如@RequiresRoles,@RequiresPermissions),
//	 * 需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 配置以下两个bean(
//	 * DefaultAdvisorAutoProxyCreator和AuthorizationAttributeSourceAdvisor)
//	 * 即可实现此功能
//	 *
//	 * @return
//	 */
//	@Bean
//	@DependsOn("lifecycleBeanPostProcessor")
//	public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() {
//		DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
//		advisorAutoProxyCreator.setProxyTargetClass(true);
//		return advisorAutoProxyCreator;
//	}
//
//	/**
//	 * 开启aop注解支持
//	 *
//	 * @param securityManager
//	 * @return
//	 */
//	@Bean
//	public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
//			DefaultWebSecurityManager securityManager) {
//		AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
//		authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
//		return authorizationAttributeSourceAdvisor;
//	}
//
///*	*//**
//	 * 注册shiroFilter
//	 * @return
//	 *//*
//	@Bean
//	public FilterRegistrationBean filterRegistrationBean() {
//	   FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
//	   DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("shiroFilterFactoryBean");
//	   delegatingFilterProxy.setTargetFilterLifecycle(true);
//	   filterRegistration.setFilter(delegatingFilterProxy);
//	   filterRegistration.setEnabled(true);
//	   filterRegistration.addUrlPatterns("/*");
//	   filterRegistration.setDispatcherTypes(DispatcherType.REQUEST);
//	   return filterRegistration;
//	}*/
//}
